package com.example.myapplication;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.view.menu.MenuAdapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.icu.text.Transliterator;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.example.myapplication.util.JsonParse;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
  //  private String[] titles = {"你好", "你好啊", "哈哈哈哈", "要快乐", "哈哈哈哈哈哈哈哈哈", "开开心心", "呵呵呵", "烦烦烦", "嘻嘻哈哈"};
    private ListView listview_iv;
    private ImageView wc_iv;
    private ImageView dd_iv;
    List<Bean.YjBean> infosFromJson;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        infosFromJson = new ArrayList<>();
        initView();

        initData();

        initEvent();

    }

    class MyBaseAdapter extends BaseAdapter {
        @Override
        public int getCount() {
            return infosFromJson.size();
        }

        @Override
        public Object getItem(int position) {
            return infosFromJson.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = View.inflate(MainActivity.this, R.layout.activity_item, null);
            Bean.YjBean yjBean = infosFromJson.get(position);
            TextView title = (TextView) view.findViewById(R.id.hello_tv);
            title.setText(yjBean.getNc());
            return view;
        }
    }

    private void initView() {
        wc_iv = findViewById(R.id.wc_iv);
        dd_iv = findViewById(R.id.dd_iv);
        listview_iv = findViewById(R.id.listview_iv);
    }

    private void initData() {
         infosFromJson = JsonParse.getInstance().getInfosFromJson(MainActivity.this);

         listview_iv.setAdapter(new MyBaseAdapter());

    }

    private void initEvent() {
        wc_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, LianxirenActivity.class);
                startActivity(intent);
            }
        });
        dd_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, DongtaiActivity.class);
                startActivity(intent);
            }
        });
    }


}
